#!/bin/bash
:<<!
脚本的测试使用如下命令：

sh ./brances_info_log_common.sh -commonFunHomeDir "${CommonFun_HomeDir_Absolute}" -branchInfoF "${Develop_Branchs_FILE_PATH}"
!



# 定义颜色常量
NC='\033[0m' # No Color
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'

function logSuccessMsg() {
    printf "${GREEN}$1${GREEN}\n${NC}"
}

function logMsg() {
    printf "$1\n${NC}"
}

function debug_log() {
    if [ "${isRelease}" == true ]; then
        echo "$1"
    fi
}

#! /bin/bash
JQ_EXEC=`which jq`


# shell 参数具名化
show_usage="args: [-commonFunHomeDir, -branchInfoF]\
                                  [--common-fun-home-dir-absolute=, --branch-info-json-file=]"
                                  
while [ -n "$1" ]
do
        case "$1" in
                -commonFunHomeDir|--common-fun-home-dir-absolute) CommonFun_HomeDir_Absolute=$2; shift 2;;
                -branchInfoF|--branch-info-json-file) Develop_Branchs_FILE_PATH=$2; shift 2;;
                --) break ;;
                *) echo $1,$2,$show_usage; break ;;
        esac
done

markdownFun_script_file_Absolute="${CommonFun_HomeDir_Absolute}/markdown/function_markdown.sh"
JsonstringFun_script_file_Absolute="${CommonFun_HomeDir_Absolute}/json_string/function_jsonstring.sh"
JsonUpdateFun_script_file_Absolute="${CommonFun_HomeDir_Absolute}/update_json_file.sh"


if [ ! -f "${markdownFun_script_file_Absolute}" ];then
    echo "❌Error:您的${markdownFun_script_file_Absolute}文件不存在，请检查！"
fi
source "${markdownFun_script_file_Absolute}" # 为了使用 markdown_fontColor 等 markdown 方法


# 更新指定文件的键值为指定值
function updateBranchResultFileKeyValue() {
    RESULT_SALE_TO_JSON_FILE_PATH=$1
    RESULT_FULL_STRING_SALE_BY_KEY=$2
    LAST_BRANCHS_INFO_STRING=$3
    
    if [ ! -f "${RESULT_SALE_TO_JSON_FILE_PATH}" ] || [ -z "${RESULT_FULL_STRING_SALE_BY_KEY}" ]; then
        echo "$FUNCNAME  提示💡💡💡：您存放分支最终结果信息的文件${RESULT_SALE_TO_JSON_FILE_PATH}不存在 或 要保存到的key值${RESULT_FULL_STRING_SALE_BY_KEY}未设置，所以所得的值将不会保存到文件中"
        return 0
    fi
    RESULT_FULL_SALE_BY_HOME_KEY=$(echo ${RESULT_FULL_STRING_SALE_BY_KEY%.*})  # %.* 表示从右边开始，删除第一个 . 号及右边的字符
    RESULT_FULL_SALE_BY_PATH_KEY=$(echo ${RESULT_FULL_STRING_SALE_BY_KEY##*.}) # *. 表示从左边开始删除最后（最右边）一个 . 号及左边的所有字符
    LAST_BRANCHS_INFO_JSON="{\"${RESULT_FULL_SALE_BY_PATH_KEY}\": \"${LAST_BRANCHS_INFO_STRING}\"}"
    sh ${bulidScriptCommon_dir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_FULL_SALE_BY_HOME_KEY}" -v "${LAST_BRANCHS_INFO_JSON}" --skip-value-check "true"
}



function getBranchPersonnelInformation() {
    PersonnelJsonMap=$1
    PersonnelKey=$2
    
    specialPersonMap=$(echo ${PersonnelJsonMap} | ${JQ_EXEC} -r --arg PersonnelKey "$PersonnelKey" '.[$PersonnelKey]')
    personnelLogResult=''
    if [ "${specialPersonMap}" != "null" ] && [ -n "${specialPersonMap}" ]; then
        branchTesterName=$(echo ${specialPersonMap} | ${JQ_EXEC} -r ".name") # -r 去除字符串引号
        if [ "${branchTesterName}" != "null" ] && [ -n "${branchTesterName}" ]; then
            personnelLogResult+="@${branchTesterName}"
        fi
    fi
}



# 获取指定单个branch的分支概要信息 {name:xxx,outline:yyy},并添加到指定的key中,而不是覆盖（测试此方法，请使用 tssh_branch_detail_info_result.sh 中已实现的单例测试)
function getSingleBranchDescription() {
    #echo "$FUNCNAME"
    while [ -n "$1" ]
    do
        case "$1" in
            -branchMap|--branchMap) branchMap=$2; shift 2;;
            -shouldMD|--should-markdown) shouldMarkdown=$2; shift 2;;
            -resultSaveToJsonF|--result-save-to-json-file-path) RESULT_BRANCH_SALE_TO_JSON_FILE_PATH=$2; shift 2;; # 为简化换行符的保真(而不是显示成换行,导致后面计算数组个数麻烦),将结果保存在的JSON文件
            -resultArrayKey|--result-array-save-by-key) RESULT_ARRAY_SALE_BY_KEY=$2; shift 2;;   # 数组结果,用什么key保存到上述文件
            -testS|--test-state) TEST_STATE=$2; shift 2;;   # 这个分支的当前测试状态(测试中、测试通过显示不同颜色)
            --) break ;;
            *) echo $1,$2; break ;;
        esac
    done


    if [ "${TEST_STATE}" == 'test_prefect' ]; then
        markdownFontColor="info"
    elif [ "${TEST_STATE}" == 'test_pass' ]; then
        markdownFontColor="info"
    elif [ "${TEST_STATE}" == 'test_submit' ]; then
        markdownFontColor="warning"
    else
        markdownFontColor="warning"
    fi
    
    branchDesResult=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".des") # -r 去除字符串引号
    branchOutlinesString=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".outlines") # -r 去除字符串引号
    if [ -z "${branchDesResult}" ] && [ -z "${branchOutlinesString}" ]; then
        Normal_BRANCH_DESCRIPT_STRING_VALUE=""
        Escape_BRANCH_DESCRIPT_STRING_VALUE="[]"
        echo "------------分支描述和概要都是空-------------\n${branchMap}"
        return 0
    fi
    
    #echo "------------分支描述或概要至少一个有值-------------"
    Normal_BRANCH_DESCRIPT_STRING_VALUE=''
    Escape_BRANCH_DESCRIPT_STRING_VALUE="["
    # 🖍：非常重要的注释(一定不要删)：经在json_string下的test里的测试脚本 test_sh_json_string.sh 中，对数组元素进行 markdown，应该在遍历markdown的过程中就遍历转义并拼接的字符串，而不能在遍历markdown的结束后，使用新的markdown元素组成的数组来遍历转义并拼接。
    if [ -n "${branchDesResult}" ] && [ "${branchDesResult}" != "详见outlines" ]; then
        branchDesResult=$(markdown_fontColor "${shouldMarkdown}" "${branchDesResult}" "${markdownFontColor}")
        Normal_BRANCH_DESCRIPT_STRING_VALUE+="${branchDesResult}\n" # 字符串拼接，不用转义
        Escape_BRANCH_DESCRIPT_STRING_VALUE+="\"${branchDesResult}\","  # 要转义
    fi
    
    if [ -n "${branchOutlinesString}" ]; then
        branchOutlinesCount=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".outlines|length")
        #echo "branchOutlinesCount=${branchOutlinesCount}"
        
        outlineIndexs="①,②,③,④,⑤,⑥,⑦,⑧,⑨,⑩"
        outlineIndexArray=(${outlineIndexs//,/ }) # 使用,替换空格，并形成数组
        #echo "***********************outlineIndexArray=${outlineIndexArray[*]}"
        
        for ((branchOutlineIndex=0;branchOutlineIndex<branchOutlinesCount;branchOutlineIndex++))
        do
            iBranchOutline_String=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".outlines[$branchOutlineIndex]")
            #echo "$((branchOutlineIndex+1)) iBranchOutline_String=${iBranchOutline_String}"
            
            if [ $branchOutlineIndex -lt ${#outlineIndexArray[@]} ]; then
                iBranchOutlineIndex=${outlineIndexArray[branchOutlineIndex]}
            else
                iBranchOutlineIndex="⑩"
            fi
            iBranchOutlineTitle=$(echo ${iBranchOutline_String} | ${JQ_EXEC} -r ".title")
            iBranchOutlineLog="${iBranchOutlineIndex}${iBranchOutlineTitle}"
            #echo "$((branchOutlineIndex+1)) iBranchOutlineLog=${iBranchOutlineLog}"
            iBranchOutlineLog=$(markdown_fontColor "${shouldMarkdown}" "${iBranchOutlineLog}" "${markdownFontColor}")

            # 重点，因为\n没法直接保真，所以要转义下(已在test_sh_brances_info_log.sh中测试过)
            Normal_BRANCH_DESCRIPT_STRING_VALUE+="${iBranchOutlineLog}\n" # 字符串拼接，不用转义
            Escape_BRANCH_DESCRIPT_STRING_VALUE+="\"${iBranchOutlineLog}\","  # 要转义
        done
    fi
    
    # 去除最后两个字符,即换行符"\n"
    if [ ${#Normal_BRANCH_DESCRIPT_STRING_VALUE} -gt 1 ]; then 
        Normal_BRANCH_DESCRIPT_STRING_VALUE=${Normal_BRANCH_DESCRIPT_STRING_VALUE: 0:${#Normal_BRANCH_DESCRIPT_STRING_VALUE}-2}
    fi
    # 去除最后一个字符,即逗号","
    if [ -n "${Escape_BRANCH_DESCRIPT_STRING_VALUE}" ] && [ "${Escape_BRANCH_DESCRIPT_STRING_VALUE}" != "[" ]; then
        Escape_BRANCH_DESCRIPT_STRING_VALUE=${Escape_BRANCH_DESCRIPT_STRING_VALUE: 0:${#Escape_BRANCH_DESCRIPT_STRING_VALUE}-1}
    fi
    Escape_BRANCH_DESCRIPT_STRING_VALUE+="]"
    
    #echo "=======当前分支的描述如下：\n无转义Normal_BRANCH_DESCRIPT_STRING_VALUE=${Normal_BRANCH_DESCRIPT_STRING_VALUE}\n有转义Escape_BRANCH_DESCRIPT_STRING_VALUE=${Escape_BRANCH_DESCRIPT_STRING_VALUE}"


    if [ -f "${RESULT_BRANCH_SALE_TO_JSON_FILE_PATH}" ] && [ -n "${Escape_BRANCH_DESCRIPT_STRING_VALUE}" ]; then
        source "${JsonstringFun_script_file_Absolute}"
#        BRANCH_OUTLINES_LOG_JSON="{\"${branchName}\": ${Escape_BRANCH_DESCRIPT_STRING_VALUE}}"
        BRANCH_OUTLINES_ELEMENT_LOG_JSON="{\"name\": \"${branchName}\", \"outline\": ${Escape_BRANCH_DESCRIPT_STRING_VALUE}}"
        BRANCH_OUTLINES_LOG_JSON="[${BRANCH_OUTLINES_ELEMENT_LOG_JSON}]"
        #echo "正在执行命令(测试分支信息的保存)：《sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_BRANCH_SALE_TO_JSON_FILE_PATH}"" -k "branch_info_result.Notification.current.branch" -v \"${BRANCH_OUTLINES_LOG_JSON}\" --skip-value-check \"true\"》"
        sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_BRANCH_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_ARRAY_SALE_BY_KEY}" -v "${BRANCH_OUTLINES_LOG_JSON}" --skip-value-check "true"

        if [ "${isRelease}" == true ]; then
            echo "恭喜:最后获取(.branch此时更新为)markdown:${shouldMarkdown}的 ${PURPLE}.${RESULT_ARRAY_SALE_BY_KEY} ${GREEN}值(在 ${BLUE}${RESULT_BRANCH_SALE_TO_JSON_FILE_PATH} ${GREEN}文件中)如下:"
            cat ${RESULT_BRANCH_SALE_TO_JSON_FILE_PATH} | jq ".${RESULT_ARRAY_SALE_BY_KEY}" | jq '.'
        fi
    fi
}


function getSingleBranchLog_flag() {
    iBranchMap=$1
    TEST_STATE=$2
    shouldMarkdown=$3

    #负责测试的人员信息
    getBranchPersonnelInformation "${iBranchMap}" "tester" # branchMap 变量需要添加引号，避免有空格影响了传入的参数的个数
    tester_info_string=${personnelLogResult}

    #提交测试的时间
    branchSubmitTestTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".submit_test_time") # -r 去除字符串引号

    branchLogFlag='null'
    if [ "${TEST_STATE}" == 'test_prefect' ]; then
        # ①添加标记📌，方便区分分支测试进展
        branchLogFlag="✅"
    
    elif [ "${TEST_STATE}" == 'test_pass' ]; then
        branchLogFlag="👌🏻"
        
    elif [ "${TEST_STATE}" == 'test_submit' ]; then
        branchLogFlag="❓"
        
        branchLogFlag+="【"  #开始标记
        # 已提测多长时间
        days_cur_to_MdDate_script_path=$(qbase -path "days_cur_to_MdDate")
        testDays=$(sh ${days_cur_to_MdDate_script_path} --Md_date "${branchSubmitTestTime}")
        #echo "${branchName}分支已提测${testDays}天"
        if [ $testDays -gt 1 ]; then
            branchLogFlag+="${testDays}天"
        else
            branchLogFlag+="今天" # 方便知道这是今天新增的提测
        fi
        
        testerName=${tester_info_string}
        if [ -n "${testerName}" ]; then
            testerName=$(markdown_fontColor "${shouldMarkdown}" "${testerName}" "warning")
            branchLogFlag+="${testerName}"
        fi
        branchLogFlag+="】"  #结束标记
    fi
}


function getSingleBranchLog_time() {
    iBranchMap=$1
    testState=$2
    showBranchTimeLog=$3
    shouldMarkdown=$4


    #提交测试的时间
    branchSubmitTestTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".submit_test_time") # -r 去除字符串引号
    #通过测试的时间
    branchPassTestTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".pass_test_time") # -r 去除字符串引号
    #合入预生产的时间
    branchMergerPreproductTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".merger_pre_time") # -r 去除字符串引号


    branchTimeLogResult=''
    if [ ${showBranchTimeLog} == 'all' ]; then
        if [ ${testState} == 'test_prefect' ]; then
            branchTimeLogResult+="[${branchSubmitTestTime}已提测]"
            branchTimeLogResult+="[${branchPassTestTime}已测试通过]"
            branchTimeLogResult+="[${branchMergerPreproductTime}已合入预生产分支]"
        elif [ ${testState} == 'test_pass' ]; then
            branchTimeLogResult+="[${branchSubmitTestTime}已提测]"
            branchTimeLogResult+="[${branchPassTestTime}已测试通过]"
        elif [ ${testState} == 'test_submit' ]; then
            branchTimeLogResult+="[${branchSubmitTestTime}已提测]"
        fi
    elif [ ${showBranchTimeLog} == 'only_last' ]; then
        if [ ${testState} == 'test_prefect' ]; then
            branchTimeLogResult+="[✅${branchMergerPreproductTime}]"
        elif [ ${testState} == 'test_pass' ]; then
            branchTimeLogResult+="[👌🏻${branchPassTestTime}]"
        elif [ ${testState} == 'test_submit' ]; then
            branchTimeLogResult+="[❓${branchSubmitTestTime}]"
        fi
    elif [ ${showBranchTimeLog} == 'none' ]; then
        branchTimeLogResult=''
    fi
    branchTimeLogResult=$(markdown_fontColor "${shouldMarkdown}" "${branchTimeLogResult}" "comment")
}

function getSingleBranchLog_at() {
    iBranchMap=$1
    shouldMarkdown=$2

    #负责测试的人员信息
    getBranchPersonnelInformation "${iBranchMap}" "tester" # branchMap 变量需要添加引号，避免有空格影响了传入的参数的个数
    tester_info_string=${personnelLogResult}

    #答疑者的人员信息
    getBranchPersonnelInformation "${iBranchMap}" "answer" # branchMap 变量需要添加引号，避免有空格影响了传入的参数的个数
    answer_info_string=${personnelLogResult}

    branchAtLogResult=''
    #答疑者的人员信息
    if [ -n "${answer_info_string}" ]; then
        personnelLogResult=$(markdown_fontColor "${shouldMarkdown}" "${answer_info_string}" "comment")
        branchAtLogResult+="${personnelLogResult}"
    fi
    
    #负责测试的人员信息
    if [ -n "${tester_info_string}" ]; then
        personnelLogResult=$(markdown_fontColor "${shouldMarkdown}" "${tester_info_string}" "comment")
        branchAtLogResult+="${personnelLogResult}"
    fi
}

function getSingleBranchLog_testState () {
    iBranchMap=$1

    # 1、获取测试状态，后面好根据不同的测试状态显示不同的样式
    testStateResult="unknow"
    #提交测试的时间
    branchSubmitTestTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".submit_test_time") # -r 去除字符串引号
    if [ "${branchSubmitTestTime}" != "null" ] && [ -n "${branchSubmitTestTime}" ]; then
        branchTimeLogResult+="[${branchSubmitTestTime}已提测]"
        testStateResult='test_submit'
    fi
    
    #通过测试的时间
    branchPassTestTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".pass_test_time") # -r 去除字符串引号
    if [ "${branchPassTestTime}" != "null" ] && [ -n "${branchPassTestTime}" ]; then
        branchTimeLogResult+="[${branchPassTestTime}已测试通过]"
        testStateResult='test_pass'
    fi
    
    #合入预生产的时间
    branchMergerPreproductTime=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".merger_pre_time") # -r 去除字符串引号
    if [ "${branchMergerPreproductTime}" != "null" ] && [ -n "${branchMergerPreproductTime}" ]; then
        branchTimeLogResult+="[${branchMergerPreproductTime}已合入预生产分支]"
        testStateResult='test_prefect'
    fi
}

# 获取指定单个branch的分支信息,并添加(而不是覆盖)保存到指定文件的指定key中
function getSingleBranchLog() {
    while [ -n "$1" ]
    do
        case "$1" in
            -iBranchMap|--iBranchMap) branchMap=$2; shift 2;;
            -showFlag|--show-branchLog-Flag) showBranchLogFlag=$2; shift 2;;
            -showName|--show-branchName) showBranchName=$2; shift 2;;
            -showTime|--show-branchTimeLog) showBranchTimeLog=$2; shift 2;;
            -showAt|--show-branchAtLog) showBranchAtLog=$2; shift 2;;
            -commonDateFunctionFilePath|--commonDateFunctionFilePath) commonDateFunctionFilePath=$2; shift 2;;
            -shouldMD|--should-markdown) shouldMarkdown=$2; shift 2;;
            -resultSaveToJsonF|--result-save-to-json-file-path) RESULT_SALE_TO_JSON_FILE_PATH=$2; shift 2;; # 为简化换行符的保真(而不是显示成换行,导致后面计算数组个数麻烦),将结果保存在的JSON文件
            -resultArrayKey|--result-array-save-by-key) RESULT_ARRAY_SALE_BY_KEY=$2; shift 2;;   # 数组结果,用什么key保存到上述文件
            --) break ;;
            *) echo $1,$2; break ;;
        esac
    done
    
    if [ -z "${branchMap}" ]; then
        Normal_BRANCH_LOG_STRING_VALUE=''
        echo "------要获取的分支输入错误，请检查！"
        return 1
    fi
    
    if [ -z "${shouldMarkdown}" ] ; then
        shouldMarkdown="false"
    fi
    

    # 1、获取测试状态，后面好根据不同的测试状态显示不同的样式
    getSingleBranchLog_testState "${iBranchMap}"
    testState=${testStateResult}

    
    # 2、获取各种信息，待后面组装使用
    # ①添加标记📌，方便区分分支测试进展（需要 tester_info_string）
    getSingleBranchLog_flag "${iBranchMap}" "${testState}" "${shouldMarkdown}"
    flag_info_string=${branchLogFlag}

    # ②分支名
    branchName=$(echo "${iBranchMap}" | ${JQ_EXEC} -r ".name") # -r 去除字符串引号
    # branchName=$(markdown_code "${shouldMarkdown}" "${branchName}")
    if [ "${testState}" == 'test_prefect' ]; then
        markdownFontColor="info"
    elif [ "${testState}" == 'test_pass' ]; then
        markdownFontColor="info"
    elif [ "${testState}" == 'test_submit' ]; then
        markdownFontColor="warning"
    else
        markdownFontColor="warning"
    fi
    branchName=$(markdown_fontColor "${shouldMarkdown}" "${branchName}" "${markdownFontColor}")

    # ③分支描述 {name:xxx,outline:yyy} ,并添加(而不是覆盖)保存到指定文件的指定key中
    getSingleBranchDescription -branchMap "${iBranchMap}" --test-state "${testState}" --should-markdown "${shouldMarkdown}" -resultSaveToJsonF "${RESULT_SALE_TO_JSON_FILE_PATH}" -resultArrayKey "${RESULT_ARRAY_SALE_BY_KEY}"
    des_info_string=${Normal_BRANCH_DESCRIPT_STRING_VALUE}
    #echo "------------分支信息:${des_info_string}"

    # ④时间线
    getSingleBranchLog_time "${iBranchMap}" "${testState}" "${showBranchTimeLog}" "${shouldMarkdown}"
    timeline_info_string=${branchTimeLogResult}

    # ⑤人员信息
    getSingleBranchLog_at "${iBranchMap}" "${shouldMarkdown}"
    at_info_string=${branchAtLogResult}

    
    
    Normal_BRANCH_LOG_STRING_VALUE='' # 赋值前先清空
    # ①添加标记📌，方便区分分支测试进展
    if [ ${showBranchLogFlag} == 'true' ] && [ -n "${flag_info_string}" ] && [ "${flag_info_string}" != 'null' ]; then
        Normal_BRANCH_LOG_STRING_VALUE+="${flag_info_string}"
    fi

    # ②是否添加分支名
    if [ "${showBranchName}" == "true" ]; then
        Normal_BRANCH_LOG_STRING_VALUE+="${branchName}:"
    fi

    # ④是否添加时间线
    if [ -n "${timeline_info_string}" ] && [ "${timeline_info_string}" != 'null' ]; then
        if [ ${showBranchTimeLog} == 'all' ]; then
            Normal_BRANCH_LOG_STRING_VALUE="${Normal_BRANCH_LOG_STRING_VALUE}${timeline_info_string}"   # 显示所有时间的时候，时间放后面
        elif [ ${showBranchTimeLog} == 'only_last' ]; then
            Normal_BRANCH_LOG_STRING_VALUE="${timeline_info_string}${Normal_BRANCH_LOG_STRING_VALUE}"  # 只显示最后时间的时候，时间放前面
        fi
    fi
    
    # ⑤是否添加at人员
    #需求方demander\开发者developer\测试人员tester\答疑者answer
    if [ ${showBranchLogFlag} == 'true' ] && [ -n "${at_info_string}" ] && [ "${at_info_string}" != 'null' ]; then
        Normal_BRANCH_LOG_STRING_VALUE+="${at_info_string}"
    fi
    
    # ③添加分支描述
    # 之前的内容存在，且超过10个字符，才需要换行
    if [ -n "${Normal_BRANCH_LOG_STRING_VALUE}" ] && [ ${#Normal_BRANCH_LOG_STRING_VALUE} -gt 10 ]; then
        Normal_BRANCH_LOG_STRING_VALUE+="\n"
    fi
    Normal_BRANCH_LOG_STRING_VALUE+="${des_info_string}"
    
    #echo "Normal_BRANCH_LOG_STRING_VALUE=${Normal_BRANCH_LOG_STRING_VALUE}" #不能写这一行，否则会多一部分
    
    return 0
}



# 获取所有分支的Log信息，并保存到指定文件中
function getAllBranchLogArray_andCategoryThem() {
    while [ -n "$1" ]
    do
        case "$1" in
            -branchMaps|--branchMap-array) branchMapArray=$2; shift 2;;
            -showCategoryName|--show-category-name) showCategoryName=$2; shift 2;;
            -showFlag|--show-branchLog-Flag) showBranchLogFlag=$2; shift 2;;
            -showName|--show-branchName) showBranchName=$2; shift 2;;
            -showTime|--show-branchTimeLog) showBranchTimeLog=$2; shift 2;;
            -showAt|--show-branchAtLog) showBranchAtLog=$2; shift 2;;
            -showTable|--show-branchTable) showBranchTable=$2; shift 2;;
            -commonDateFunctionFilePath|--commonDateFunctionFilePath) commonDateFunctionFilePath=$2; shift 2;;
            -shouldMD|--should-markdown) shouldMarkdown=$2; shift 2;;
            -resultSaveToJsonF|--result-save-to-json-file-path) RESULT_SALE_TO_JSON_FILE_PATH=$2; shift 2;; # 为简化换行符的保真(而不是显示成换行,导致后面计算数组个数麻烦),将结果保存在的JSON文件
            -resultBranchKey|--result-branch-array-save-by-key) RESULT_BRANCH_ARRAY_SALE_BY_KEY=$2; shift 2;;   # 分支branch元素数组结果,用什么key保存到上述文件
            -resultCategoryKey|--result-category-array-save-by-key) RESULT_CATEGORY_ARRAY_SALE_BY_KEY=$2; shift 2;;   # 分类category元素数组结果,用什么key保存到上述文件
            -resultFullKey|--result-full-string-save-by-key) RESULT_FULL_STRING_SALE_BY_KEY=$2; shift 2;;   # 总字符串结果,用什么key保存到上述文件
            --) break ;;
        esac
    done

    if [ -z "${showCategoryName}" ]; then   # 避免外面没传值
        showCategoryName="false"
    fi
    
    #echo "要获取信息的所有分支数组branchMapArray=${branchMapArray}"
    if [ -z "${branchMapArray}" ] || [ "${branchMapArray}" == "null" ]; then
        echo "-------------------------💡💡💡tips: input is empty"
        branchMapArray="" # 写此行，只是为了将 "null" 也设置成空字符串
        updateBranchResultFileKeyValue "${RESULT_SALE_TO_JSON_FILE_PATH}" "${RESULT_FULL_STRING_SALE_BY_KEY}" ""
        return 0
    fi

    # 获取分类 category 的值
    # 注意📢:赋值前先清空数据，避免其他接口也调用此方法，导致有残留数据
    categoryBranchsLogArray_hotfix=()
    categoryBranchsLogArray_feature=()
    categoryBranchsLogArray_optimize=()
    categoryBranchsLogArray_other=()
    
    Escape_CATEGORY_STRING_VALUE_hotfix="["
    Escape_CATEGORY_STRING_VALUE_feature="["
    Escape_CATEGORY_STRING_VALUE_optimize="["
    Escape_CATEGORY_STRING_VALUE_other="["
    
    branchCount=$(echo ${branchMapArray} | ${JQ_EXEC} -r ".|length")
    #echo "branchCount=${branchCount}"
    for ((logBranchIndex=0;logBranchIndex<branchCount;logBranchIndex++)) # 注意📢:取名logBranchIndex，而不用i避免被getSingleBranchLog中的getSingleBranchDescription的i给影响了
    do
        iBranchMap=$(echo ${branchMapArray} | ${JQ_EXEC} -r ".[$((logBranchIndex))]") # -r 去除字符串引号
        #echo "正在执行命令(获取单分支信息,并添加(而不是覆盖)保存到 ${RESULT_SALE_TO_JSON_FILE_PATH} 文件的 ${RESULT_BRANCH_ARRAY_SALE_BY_KEY} 中)：《 getSingleBranchLog -iBranchMap \"${iBranchMap}\" -showFlag \"${showBranchLogFlag}\" -showName \"${showBranchName}\" -showTime \"${showBranchTimeLog}\" -showAt \"${showBranchAtLog}\" -commonDateFunctionFilePath \"${commonDateFunctionFilePath}\" -shouldMD \"${shouldMarkdown}\" -resultSaveToJsonF \"${RESULT_SALE_TO_JSON_FILE_PATH}\" 》"
        getSingleBranchLog -iBranchMap "${iBranchMap}" -showFlag "${showBranchLogFlag}" -showName "${showBranchName}" -showTime "${showBranchTimeLog}" -showAt "${showBranchAtLog}" -commonDateFunctionFilePath "${commonDateFunctionFilePath}" -shouldMD "${shouldMarkdown}" -resultSaveToJsonF "${RESULT_SALE_TO_JSON_FILE_PATH}" -resultArrayKey "${RESULT_BRANCH_ARRAY_SALE_BY_KEY}"
        if [ $logBranchIndex -eq $((branchCount-1)) ]; then #如果已经全部添加完，则可以一次性输出最新的了
            logSuccessMsg "恭喜:最后获取(.branch)markdown:${shouldMarkdown}的 ${PURPLE}.${RESULT_BRANCH_ARRAY_SALE_BY_KEY} ${GREEN}值(在 ${BLUE}${RESULT_SALE_TO_JSON_FILE_PATH} ${GREEN}文件中)如下:"
            cat ${RESULT_SALE_TO_JSON_FILE_PATH} | jq ".${RESULT_BRANCH_ARRAY_SALE_BY_KEY}" | jq '.'
        fi
                
        #echo "第${logBranchIndex}个分支的分支信息为-----------------${Normal_BRANCH_LOG_STRING_VALUE}" # 使用echo做函数返回值，所以不能写此行，除非你是在调试中用于临时查看一些信息
        iBranchLog=${Normal_BRANCH_LOG_STRING_VALUE}
#            if [ $logBranchIndex -eq 0 ]; then
#                echo "\n"
#            fi
#            echo "===============分支信息结果(未归类前的顺序)$((logBranchIndex+1)) ${iBranchLog}"
#            if [ $logBranchIndex -eq $((branchCount-1)) ]; then
#                echo "\n"
#            fi
        
        branchType=$(echo ${iBranchMap} | ${JQ_EXEC} -r ".type") # -r 去除字符串引号
        #echo ".............branchType=${branchType}"
        if [ "${branchType}" == "hotfix" ]; then
            categoryBranchsLogArray_hotfix[${#categoryBranchsLogArray_hotfix[@]}]="${iBranchLog}"
            Escape_CATEGORY_STRING_VALUE_hotfix+="\"${iBranchLog}\","  # 要转义
        elif [ "${branchType}" == "feature" ]; then
            categoryBranchsLogArray_feature[${#categoryBranchsLogArray_feature[@]}]="${iBranchLog}"
            Escape_CATEGORY_STRING_VALUE_feature+="\"${iBranchLog}\","  # 要转义
        elif [ "${branchType}" == "optimize" ]; then
            categoryBranchsLogArray_optimize[${#categoryBranchsLogArray_optimize[@]}]="${iBranchLog}"
            Escape_CATEGORY_STRING_VALUE_optimize+="\"${iBranchLog}\","  # 要转义
        else
            categoryBranchsLogArray_other[${#categoryBranchsLogArray_other[@]}]="${iBranchLog}"
            Escape_CATEGORY_STRING_VALUE_other+="\"${iBranchLog}\","  # 要转义
        fi
    done
    # 去除最后一个字符,即逗号","
    if [ -n "${Escape_CATEGORY_STRING_VALUE_hotfix}" ] && [ "${Escape_CATEGORY_STRING_VALUE_hotfix}" != "[" ]; then
        Escape_CATEGORY_STRING_VALUE_hotfix=${Escape_CATEGORY_STRING_VALUE_hotfix: 0:${#Escape_CATEGORY_STRING_VALUE_hotfix}-1}
    fi
    if [ -n "${Escape_CATEGORY_STRING_VALUE_feature}" ] && [ "${Escape_CATEGORY_STRING_VALUE_feature}" != "[" ]; then
        Escape_CATEGORY_STRING_VALUE_feature=${Escape_CATEGORY_STRING_VALUE_feature: 0:${#Escape_CATEGORY_STRING_VALUE_feature}-1}
    fi
    if [ -n "${Escape_CATEGORY_STRING_VALUE_optimize}" ] && [ "${Escape_CATEGORY_STRING_VALUE_optimize}" != "[" ]; then
        Escape_CATEGORY_STRING_VALUE_optimize=${Escape_CATEGORY_STRING_VALUE_optimize: 0:${#Escape_CATEGORY_STRING_VALUE_optimize}-1}
    fi
    if [ -n "${Escape_CATEGORY_STRING_VALUE_other}" ] && [ "${Escape_CATEGORY_STRING_VALUE_other}" != "[" ]; then
        Escape_CATEGORY_STRING_VALUE_other=${Escape_CATEGORY_STRING_VALUE_other: 0:${#Escape_CATEGORY_STRING_VALUE_other}-1}
    fi
    Escape_CATEGORY_STRING_VALUE_hotfix+="]"
    Escape_CATEGORY_STRING_VALUE_feature+="]"
    Escape_CATEGORY_STRING_VALUE_optimize+="]"
    Escape_CATEGORY_STRING_VALUE_other+="]"
    #echo "hotfix  分类信息----------\n${Escape_CATEGORY_STRING_VALUE_hotfix}"
    #echo "feature 分类信息----------\n${Escape_CATEGORY_STRING_VALUE_feature}"
    #echo "optimize分类信息----------\n${Escape_CATEGORY_STRING_VALUE_optimize}"
    #echo "other   分类信息----------\n${Escape_CATEGORY_STRING_VALUE_other}"
    
    # 设置分类 category 的值到FILE中
    if [ ! -f "${RESULT_SALE_TO_JSON_FILE_PATH}" ] || [ -z "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" ]; then
        echo "$FUNCNAME  提示💡💡💡：您存放每个分支信息的文件${RESULT_SALE_TO_JSON_FILE_PATH}不存在 或 要保存到的key值${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}未设置，所以所得的值将不会保存到文件中"
        return 0
    fi
    # 在文件和key值存在的前提下
    source "${JsonstringFun_script_file_Absolute}"
    if [ -f "${RESULT_SALE_TO_JSON_FILE_PATH}" ] && [ -n "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" ]; then
        if [ -n "${Escape_CATEGORY_STRING_VALUE_hotfix}" ]; then
            CATEGORY_BRANCHS_LOG_JSON_hotfix="{\"hotfix\": ${Escape_CATEGORY_STRING_VALUE_hotfix}}"
            sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" -v "${CATEGORY_BRANCHS_LOG_JSON_hotfix}" --skip-value-check "true"
        fi
        if [ -n "${Escape_CATEGORY_STRING_VALUE_feature}" ]; then
            CATEGORY_BRANCHS_LOG_JSON_feature="{\"feature\": ${Escape_CATEGORY_STRING_VALUE_feature}}"
            sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" -v "${CATEGORY_BRANCHS_LOG_JSON_feature}" --skip-value-check "true"
        fi
        if [ -n "${Escape_CATEGORY_STRING_VALUE_optimize}" ]; then
            CATEGORY_BRANCHS_LOG_JSON_optimize="{\"optimize\": ${Escape_CATEGORY_STRING_VALUE_optimize}}"
            sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" -v "${CATEGORY_BRANCHS_LOG_JSON_optimize}" --skip-value-check "true"
        fi
        if [ -n "${Escape_CATEGORY_STRING_VALUE_other}" ]; then
            CATEGORY_BRANCHS_LOG_JSON_other="{\"other\": ${Escape_CATEGORY_STRING_VALUE_other}}"
            sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" -v "${CATEGORY_BRANCHS_LOG_JSON_other}" --skip-value-check "true"
        fi
    fi


   # echo "categoryBranchsLogArray_hotfix=${#categoryBranchsLogArray_hotfix[*]}个元素 ${categoryBranchsLogArray_hotfix[*]}"
   # echo "categoryBranchsLogArray_feature=${#categoryBranchsLogArray_feature[*]}个元素 ${categoryBranchsLogArray_feature[*]}"
   # echo "categoryBranchsLogArray_optimize=${#categoryBranchsLogArray_optimize[*]}个元素 ${categoryBranchsLogArray_optimize[*]}"
   # echo "categoryBranchsLogArray_other=${#categoryBranchsLogArray_other[*]}个元素 ${categoryBranchsLogArray_other[*]}"
    logSuccessMsg "恭喜:最后获取(.category)markdown:${shouldMarkdown}的 ${PURPLE}.${RESULT_CATEGORY_ARRAY_SALE_BY_KEY} ${GREEN}值(在 ${BLUE}${RESULT_SALE_TO_JSON_FILE_PATH} ${GREEN}文件中)如下:"
    cat ${RESULT_SALE_TO_JSON_FILE_PATH} | jq ".${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" | jq '.'
}



# 获取指定分类category数组的分支信息
function getCategoryBranchsLog() {
    while [ -n "$1" ]
    do
            case "$1" in
                    #-categoryBranchsLogArray|--categoryBranchsLog-array) categoryBranchsLogArrayString=$2; shift 2;;
                    -categoryJsonF|--category-json-file-path) CATEGORY_JSON_FILE_PATH=$2; shift 2;; # 分类category数组所在的文件
                    -categoryArrayKey|--category-array-key) CATEGORY_ARRAY_KEY=$2; shift 2;;   # 分类category数组在文件中使用的key
                    
                    -categoryName|--category-name) categoryName=$2; shift 2;;

                    -showCategoryName|--show-category-name) showCategoryName=$2; shift 2;;
                    -lastLogIndexInAll|--lastLogIndexInAll) lastLogIndexInAll=$2; shift 2;;
                    --) break ;;
            esac
    done

    # 初始赋值，避免其他类也使用此方法，导致数组错误
    categoryBranchsLogsResult=''
    Escape_CATEGORY_BRANCH_ARRAY_STRING='' # 有逗号分隔的待添加到数组中的值
    lastLogIndexInAllReslut=${lastLogIndexInAll}

    if [ ! -f "${CATEGORY_JSON_FILE_PATH}" ]; then
        echo "$FUNCNAME ❌Error:您存放分类分支信息的文件${CATEGORY_JSON_FILE_PATH}，不存在，请检查文件！"
        return 1
    fi

    #echo "正在执行命令(获取分类分组信息)：《cat ${CATEGORY_JSON_FILE_PATH} | ${JQ_EXEC} ".${CATEGORY_ARRAY_KEY}.${categoryName}"》"
    #echo "正在执行命令(获取分类分支个数)：《cat ${CATEGORY_JSON_FILE_PATH} | ${JQ_EXEC} ".${CATEGORY_ARRAY_KEY}.${categoryName}" | ${JQ_EXEC} -r ".|length"》"
    categoryBranchsLogCount=$(cat ${CATEGORY_JSON_FILE_PATH} | ${JQ_EXEC} ".${CATEGORY_ARRAY_KEY}.${categoryName}" | ${JQ_EXEC} ".|length")
    #echo "${CATEGORY_JSON_FILE_PATH}文件中在${CATEGORY_ARRAY_KEY}下的${categoryName}分类的分支个数=============${categoryBranchsLogCount}个"
    if [ ${categoryBranchsLogCount} -eq 0 ]; then
        debug_log "提示💡💡💡： ${CATEGORY_JSON_FILE_PATH} 文件中在 ${CATEGORY_ARRAY_KEY} 下没有 ${BLUE}${categoryName}${NC} 属性的数据"
        return 0
    fi

    if [ "${showCategoryName}" == "true" ]; then
        categoryHeaderString="=======${categoryName}======="
        categoryBranchsLogsResult="${categoryHeaderString}\n"
        Escape_CATEGORY_BRANCH_ARRAY_STRING="\"${categoryHeaderString}\","
    fi

    # 要先判空才能获取
    categoryBranchsLogArray=$(cat ${CATEGORY_JSON_FILE_PATH} | ${JQ_EXEC} -r ".${CATEGORY_ARRAY_KEY}.${categoryName}")
    for ((categoryIndex=0;categoryIndex<categoryBranchsLogCount;categoryIndex++))
    do
        # iBranchLog=${categoryBranchsLogArray[categoryIndex]} # Error：多个时候，只能取到第一个
        # 由base目录下update_value/test文件夹里的 tssh_update_text_variable.sh 脚本，我们知道
        # 我们知道使用jquery取值的不要使用 jq -r 属性，且需要先去除前后的双引号再去操作字符串。这样的好处有：
        # 好处①：设置 json 的时候，仍然保留原本的在前后都要加双引号的操作。
        # 好处②：当要对所取到的值修改后再更新回json文件时候，可以成功"
        iBranchLog_withEscape=$(cat ${CATEGORY_JSON_FILE_PATH} | ${JQ_EXEC} ".${CATEGORY_ARRAY_KEY}.${categoryName}" | ${JQ_EXEC} ".[${categoryIndex}]")
        # help echo
        # echo "======iBranchLog_withEscape=${iBranchLog_withEscape}"
        # echo "======iBranchLog_withEscape_echo=${iBranchLog_withEscape//\\n/\\\\n}" # 这里转义换行符只是为了 echo 显示而已，没其他用处
        iBranchLog_withEscape_noDoubleQuote=${iBranchLog_withEscape: 1:${#iBranchLog_withEscape}-2}
        # echo "======iBranchLog_withEscape_noDoubleQuote=${iBranchLog_withEscape_noDoubleQuote}"
        # echo "======iBranchLog_withEscape_noDoubleQuote_echo=${iBranchLog_withEscape_noDoubleQuote//\\n/\\\\n}" # 这里转义换行符只是为了 echo 显示而已，没其他用处
        iBranchLog=${iBranchLog_withEscape_noDoubleQuote}

        #echo "${categoryName}分类中的第$((categoryIndex+1))个分支的信息 iBranchsLog=${iBranchLog}"
        iBranchLog="$((lastLogIndexInAll+1)).${iBranchLog}"
        categoryBranchsLogsResult+="${iBranchLog}\n"
        Escape_CATEGORY_BRANCH_ARRAY_STRING+="\"${iBranchLog}\","

        lastLogIndexInAll=$((lastLogIndexInAll+1))
    done
    
    # 去除最后两个字符,即换行符"\n"
    if [ -n "${categoryBranchsLogsResult}" ]; then
        categoryBranchsLogsResult=${categoryBranchsLogsResult: 0:${#categoryBranchsLogsResult}-2}
    fi
    #echo "${CATEGORY_JSON_FILE_PATH}文件中在${CATEGORY_ARRAY_KEY}下的${categoryName}分类的分支信息=============${categoryBranchsLogsResult}" #不能写这一行，否则会多一部分,因为这里我们使用echo做函数返回值，所以不能写此行，除非你是在调试中用于临时查看一些信息
    

    lastLogIndexInAllReslut=${lastLogIndexInAll}
    return 0
}


# 通过分类顺序，获取所有分支信息
function getAllCategoryBranchLog() {
    while [ -n "$1" ]
    do
            case "$1" in
                    -categoryJsonF|--category-json-file-path) CATEGORY_JSON_FILE_PATH=$2; shift 2;; # 分类category数组所在的文件
                    -categoryArrayKey|--category-array-key) CATEGORY_ARRAY_KEY=$2; shift 2;;   # 分类category数组在文件中使用的key
                    -showCategoryName|--show-category-name) showCategoryName=$2; shift 2;;
                    -resultFullKey|--result-full-string-save-by-key) RESULT_FULL_STRING_SALE_BY_KEY=$2; shift 2;;   # 总字符串结果,用什么key保存到上述文件
                    
                    --) break ;;
            esac
    done

    # 总分类字符串
    ALL_CATEGORY_BRANCH_STRING=''
    Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING=''

    if [ ! -f "${CATEGORY_JSON_FILE_PATH}" ]; then
        echo "$FUNCNAME ❌Error:您存放分类分支信息的文件${CATEGORY_JSON_FILE_PATH}，不存在，请检查文件！"
        return 1
    fi
    

    lastLogIndex=0
    # 获取 hotfix 分类的信息
    #echo "正在执行《getCategoryBranchsLog -categoryJsonF \"${CATEGORY_JSON_FILE_PATH}\" -categoryArrayKey \"${CATEGORY_ARRAY_KEY}\" -categoryName 'hotfix' -lastLogIndexInAll "${lastLogIndex}" -showCategoryName \"${showCategoryName}\"》"
    getCategoryBranchsLog -categoryJsonF "${CATEGORY_JSON_FILE_PATH}" -categoryArrayKey "${CATEGORY_ARRAY_KEY}" -categoryName 'hotfix' -lastLogIndexInAll "${lastLogIndex}" -showCategoryName "${showCategoryName}"
    if [ $? == 0 ] && [ -n "${categoryBranchsLogsResult}" ]; then
        if [ -n "${ALL_CATEGORY_BRANCH_STRING}" ]; then
            ALL_CATEGORY_BRANCH_STRING+='\n'
        fi
        ALL_CATEGORY_BRANCH_STRING+="${categoryBranchsLogsResult}"
        Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING+="${Escape_CATEGORY_BRANCH_ARRAY_STRING}" # 已符合转义并加了逗号,
    fi
    lastLogIndex=${lastLogIndexInAllReslut}
    
    getCategoryBranchsLog -categoryJsonF "${CATEGORY_JSON_FILE_PATH}" -categoryArrayKey "${CATEGORY_ARRAY_KEY}" -categoryName 'feature' -lastLogIndexInAll "${lastLogIndex}" -showCategoryName "${showCategoryName}"
    if [ $? == 0 ] && [ -n "${categoryBranchsLogsResult}" ]; then
        if [ -n "${ALL_CATEGORY_BRANCH_STRING}" ]; then
            ALL_CATEGORY_BRANCH_STRING+='\n'
        fi
        ALL_CATEGORY_BRANCH_STRING+=${categoryBranchsLogsResult}
        Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING+="${Escape_CATEGORY_BRANCH_ARRAY_STRING}" # 已符合转义并加了逗号,
    fi
    lastLogIndex=${lastLogIndexInAllReslut}
    
    getCategoryBranchsLog -categoryJsonF "${CATEGORY_JSON_FILE_PATH}" -categoryArrayKey "${CATEGORY_ARRAY_KEY}" -categoryName 'optimize' -lastLogIndexInAll "${lastLogIndex}" -showCategoryName "${showCategoryName}"
    if [ $? == 0 ] && [ -n "${categoryBranchsLogsResult}" ]; then
        if [ -n "${ALL_CATEGORY_BRANCH_STRING}" ]; then
            ALL_CATEGORY_BRANCH_STRING+='\n'
        fi
        ALL_CATEGORY_BRANCH_STRING+=${categoryBranchsLogsResult}
        Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING+="${Escape_CATEGORY_BRANCH_ARRAY_STRING}" # 已符合转义并加了逗号,
    fi
    lastLogIndex=${lastLogIndexInAllReslut}
    
    getCategoryBranchsLog -categoryJsonF "${CATEGORY_JSON_FILE_PATH}" -categoryArrayKey "${CATEGORY_ARRAY_KEY}" -categoryName 'other' -lastLogIndexInAll "${lastLogIndex}" -showCategoryName "${showCategoryName}"
    if [ $? == 0 ] && [ -n "${categoryBranchsLogsResult}" ]; then
        if [ -n "${ALL_CATEGORY_BRANCH_STRING}" ]; then
            ALL_CATEGORY_BRANCH_STRING+='\n'
        fi
        ALL_CATEGORY_BRANCH_STRING+=${categoryBranchsLogsResult}
        Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING+="${Escape_CATEGORY_BRANCH_ARRAY_STRING}" # 已符合转义并加了逗号,
    fi
    lastLogIndex=${lastLogIndexInAllReslut}

    if [ -z "${ALL_CATEGORY_BRANCH_STRING}" ]; then
        ALL_CATEGORY_BRANCH_STRING="tips: no any branchs info"
    fi
    #echo "通过分类顺序，获取到的所有分支信息ALL_CATEGORY_BRANCH_STRING=\n${ALL_CATEGORY_BRANCH_STRING}"

    # if [ -f "${RESULT_SALE_TO_JSON_FILE_PATH}" ] && [ -n "${RESULT_FULL_STRING_SALE_BY_KEY}" ]; then
    #     RESULT_FULL_SALE_BY_HOME_KEY=$(echo ${RESULT_FULL_STRING_SALE_BY_KEY%.*})  # %.* 表示从右边开始，删除第一个 . 号及右边的字符
    #     RESULT_FULL_SALE_BY_PATH_KEY=$(echo ${RESULT_FULL_STRING_SALE_BY_KEY##*.}) # *. 表示从左边开始删除最后（最右边）一个 . 号及左边的所有字符
    #     #echo "结果字符串的保存位置=${RESULT_FULL_SALE_BY_HOME_KEY}------${RESULT_FULL_SALE_BY_HOME_KEY}"
    #     LAST_BRANCHS_INFO_JSON="{\"${RESULT_FULL_SALE_BY_PATH_KEY}\": \"${ALL_CATEGORY_BRANCH_STRING}\"}"
    #     sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_FULL_SALE_BY_HOME_KEY}" -v "${LAST_BRANCHS_INFO_JSON}" --skip-value-check "true"

    #     # 去除最后一个字符,即逗号","
    #     if [ -n "${Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING}" ] && [ "${Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING}" != "[" ]; then
    #         Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING=${Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING: 0:${#Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING}-1}
    #     fi
    #     Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING="[${Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING}]" # 内部已符合转义并加了逗号,现在补充上前后的[]
    #     Escape_ALL_CATEGORY_BRANCH_ARRAY_JSON="{\"${RESULT_FULL_SALE_BY_PATH_KEY}_slice\": ${Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING}}"
    #     sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_FULL_SALE_BY_HOME_KEY}" -v "${Escape_ALL_CATEGORY_BRANCH_ARRAY_JSON}" --skip-value-check "true"
    # fi
}



function getAllBranchLogString() {
    while [ -n "$1" ]
    do
        case "$1" in
            -branchMaps|--branchMap-array) branchMapArray=$2; shift 2;;
            -showCategoryName|--show-category-name) showCategoryName=$2; shift 2;;
            -showFlag|--show-branchLog-Flag) showBranchLogFlag=$2; shift 2;;
            -showName|--show-branchName) showBranchName=$2; shift 2;;
            -showTime|--show-branchTimeLog) showBranchTimeLog=$2; shift 2;;
            -showAt|--show-branchAtLog) showBranchAtLog=$2; shift 2;;
            -showTable|--show-branchTable) showBranchTable=$2; shift 2;;
            -commonDateFunctionFilePath|--commonDateFunctionFilePath) commonDateFunctionFilePath=$2; shift 2;;
            -shouldMD|--should-markdown) shouldMarkdown=$2; shift 2;;
            -resultSaveToJsonF|--result-save-to-json-file-path) RESULT_SALE_TO_JSON_FILE_PATH=$2; shift 2;; # 为简化换行符的保真(而不是显示成换行,导致后面计算数组个数麻烦),将结果保存在的JSON文件
            -resultBranchKey|--result-branch-array-save-by-key) RESULT_BRANCH_ARRAY_SALE_BY_KEY=$2; shift 2;;   # 分支branch元素数组结果,用什么key保存到上述文件
            -resultCategoryKey|--result-category-array-save-by-key) RESULT_CATEGORY_ARRAY_SALE_BY_KEY=$2; shift 2;;   # 分类category元素数组结果,用什么key保存到上述文件
            -resultFullKey|--result-full-string-save-by-key) RESULT_FULL_STRING_SALE_BY_KEY=$2; shift 2;;   # 总字符串结果,用什么key保存到上述文件
            --) break ;;
        esac
    done

    #echo "要获取信息的所有分支数组branchMapArray=${branchMapArray}"
    if [ -z "${branchMapArray}" ] || [ "${branchMapArray}" == "null" ]; then
        echo "-------------------------💡💡💡tips: input is empty"
        branchMapArray="" # 写此行，只是为了将 "null" 也设置成空字符串
        LAST_BRANCHS_INFO_STRING=""
        updateBranchResultFileKeyValue "${RESULT_SALE_TO_JSON_FILE_PATH}" "${RESULT_FULL_STRING_SALE_BY_KEY}" ""
        return 0
    fi


    getAllBranchLogArray_andCategoryThem -branchMaps "${branchMapArray}" -showCategoryName "${showCategoryName}" -showFlag "${showBranchLogFlag}" -showName "${showBranchName}" -showTime "${showBranchTimeLog}" -showAt "${showBranchAtLog}" -showTable "${showBranchTable}" -commonDateFunctionFilePath "${commonDateFunctionFilePath}" -shouldMD "${shouldMarkdown}" -resultSaveToJsonF "${RESULT_SALE_TO_JSON_FILE_PATH}" -resultBranchKey "${RESULT_BRANCH_ARRAY_SALE_BY_KEY}" -resultCategoryKey "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" -resultFullKey "${RESULT_FULL_STRING_SALE_BY_KEY}"
    if [ $? != 0 ]; then
        echo "$FUNCNAME ❌Error:获取所有分支的Log信息，并保存到指定文件中！"
        return 1
    fi


    
    LAST_BRANCHS_INFO_STRING=""
    Escape_LAST_BRANCH_ARRAY_ONLY_STRING=""
    debug_log "正在执行命令(获取指定文件下所有category分类里的分支信息，获取后会将拼装值保存起来到文件里)：《getAllCategoryBranchLog -categoryJsonF \"${RESULT_SALE_TO_JSON_FILE_PATH}\" -categoryArrayKey \"${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}\" -showCategoryName \"${showCategoryName}\"》"
    getAllCategoryBranchLog -categoryJsonF "${RESULT_SALE_TO_JSON_FILE_PATH}" -categoryArrayKey "${RESULT_CATEGORY_ARRAY_SALE_BY_KEY}" -showCategoryName "${showCategoryName}" -resultFullKey "${RESULT_FULL_STRING_SALE_BY_KEY}"
    if [ $? != 0 ]; then
        echo "$FUNCNAME ❌Error:执行 getAllCategoryBranchLog 进行分类发生错误！"
        return 1
    fi
    #echo "=========getAllCategoryBranchLog_echo 获取到的为:${ALL_CATEGORY_BRANCH_STRING//\\n/\\\\n}》"
    

    LAST_BRANCHS_INFO_STRING+=${ALL_CATEGORY_BRANCH_STRING}
    Escape_LAST_BRANCH_ARRAY_ONLY_STRING+=${Escape_ALL_CATEGORY_BRANCH_ARRAY_STRING}

    if [ "${showBranchTable}" == "true" ]; then
        sh ${CurrentDIR_Script_Absolute}/branch_info_table.sh "${branchMapArray}"
        tableString=${BranchTableInfoResult}
        LAST_BRANCHS_INFO_STRING="${tableString}\n${LAST_BRANCHS_INFO_STRING}"
    fi
    # tableString="我是测试的表格数据(测试通过✅)"
    # Escape_LAST_BRANCH_ARRAY_ONLY_STRING="\"${tableString}\",${Escape_LAST_BRANCH_ARRAY_ONLY_STRING}"

    if [ -f "${RESULT_SALE_TO_JSON_FILE_PATH}" ] && [ -n "${RESULT_FULL_STRING_SALE_BY_KEY}" ]; then
        RESULT_FULL_SALE_BY_HOME_KEY=$(echo ${RESULT_FULL_STRING_SALE_BY_KEY%.*})  # %.* 表示从右边开始，删除第一个 . 号及右边的字符
        RESULT_FULL_SALE_BY_PATH_KEY=$(echo ${RESULT_FULL_STRING_SALE_BY_KEY##*.}) # *. 表示从左边开始删除最后（最右边）一个 . 号及左边的所有字符
        #echo "结果字符串的保存位置=${RESULT_FULL_SALE_BY_HOME_KEY}------${RESULT_FULL_SALE_BY_HOME_KEY}"
        LAST_BRANCHS_INFO_JSON="{\"${RESULT_FULL_SALE_BY_PATH_KEY}\": \"${LAST_BRANCHS_INFO_STRING}\"}"
        sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_FULL_SALE_BY_HOME_KEY}" -v "${LAST_BRANCHS_INFO_JSON}" --skip-value-check "true"
        logSuccessMsg "恭喜:最后获取(.full)markdown:${shouldMarkdown}的 ${PURPLE}.${RESULT_FULL_SALE_BY_HOME_KEY}.${RESULT_FULL_SALE_BY_PATH_KEY} ${GREEN}值(在 ${BLUE}${RESULT_SALE_TO_JSON_FILE_PATH} ${GREEN}文件中)如下:"
        cat ${RESULT_SALE_TO_JSON_FILE_PATH} | jq ".${RESULT_FULL_SALE_BY_HOME_KEY}.${RESULT_FULL_SALE_BY_PATH_KEY}" | jq '.'

        # 去除最后一个字符,即逗号","
        RESULT_FULL_SLIECE_SALE_BY_PATH_KEY="${RESULT_FULL_SALE_BY_PATH_KEY}_slice"
        if [ -n "${Escape_LAST_BRANCH_ARRAY_ONLY_STRING}" ] && [ "${Escape_LAST_BRANCH_ARRAY_ONLY_STRING}" != "[" ]; then
            Escape_LAST_BRANCH_ARRAY_ONLY_STRING=${Escape_LAST_BRANCH_ARRAY_ONLY_STRING: 0:${#Escape_LAST_BRANCH_ARRAY_ONLY_STRING}-1}
        fi
        Escape_LAST_BRANCH_ARRAY_STRING="[${Escape_LAST_BRANCH_ARRAY_ONLY_STRING}]" # 内部已符合转义并加了逗号,现在补充上前后的[]
        Escape_LAST_BRANCH_ARRAY_JSON="{\"${RESULT_FULL_SLIECE_SALE_BY_PATH_KEY}\": ${Escape_LAST_BRANCH_ARRAY_STRING}}"
        sh ${CommonFun_HomeDir_Absolute}/update_json_file.sh -f "${RESULT_SALE_TO_JSON_FILE_PATH}" -k "${RESULT_FULL_SALE_BY_HOME_KEY}" -v "${Escape_LAST_BRANCH_ARRAY_JSON}" --skip-value-check "true"
        logSuccessMsg "恭喜:最后获取(.full_slice)markdown:${shouldMarkdown}的 ${PURPLE}.${RESULT_FULL_SALE_BY_HOME_KEY}.${RESULT_FULL_SLIECE_SALE_BY_PATH_KEY} ${GREEN}值(在 ${BLUE}${RESULT_SALE_TO_JSON_FILE_PATH} ${GREEN}文件中)如下:"
        cat ${RESULT_SALE_TO_JSON_FILE_PATH} | jq ".${RESULT_FULL_SALE_BY_HOME_KEY}.${RESULT_FULL_SLIECE_SALE_BY_PATH_KEY}" | jq '.'
    fi


    # fileValue_origin_withDoubleQuote=${Escape_LAST_BRANCH_ARRAY_ONLY_STRING}
    #echo "======fileValue_origin_withDoubleQuote=${fileValue_origin_withDoubleQuote}"
    # echo "======fileValue_origin_withDoubleQuote_echo=${fileValue_origin_withDoubleQuote//\\n/\\\\n}" # 这里转义换行符只是为了 echo 显示而已，没其他用处
    # Escape_LAST_BRANCH_ARRAY_ONLY_STRING_noDoubleQuote=${Escape_LAST_BRANCH_ARRAY_ONLY_STRING: 1:${#Escape_LAST_BRANCH_ARRAY_ONLY_STRING}-2} # 去掉前后的双引号
}
